﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IssueIT.Core.Domain.Exceptions;
using IssueIT.Core.Domain.Model;
using NUnit.Framework;
using Should;

namespace IssueIT.Core.Tests.Domain
{
	[TestFixture]
	internal class IssueFixture
	{
		private Issue GetTestIssue()
		{
			User tester = User.Unknown;
			Post post = Post.NewPost(tester);

			Issue issue = new Issue(post);

			return issue;
		}

		//todo start her
		[Test]
		public void Can_create_Issue()
		{
			var classUnderTest = GetTestIssue();

			classUnderTest.Revision.ShouldNotEqual(Guid.Empty);
		}

		[Test]
		public void Add_Post_Will_Update_Issue_Revision()
		{
			User nextUser = new User("email@test.com", "Henrik", Company.Any);
			Issue issue = GetTestIssue();
			Guid lastRevision = issue.Revision;
			Post nextPost = Post.NewPost(nextUser);
			issue.AddPost(nextPost, lastRevision);

			issue.Revision.ShouldEqual(nextPost.Id);
		}

		[Test]
		[ExpectedException(typeof(IssueHasBeenUpdatedException))]
		public void Add_Post_To_Old_revision_Will_Throw_Exception()
		{
			User nextUser = new User("email@test.com", "My name", Company.Any);
			Issue issue = GetTestIssue();
			Guid lastRevision = issue.Revision;

			Post nextPost = Post.NewPost(nextUser);
			issue.AddPost(nextPost, lastRevision);

			Post yetAnotherPost = Post.NewPost(nextUser);
			issue.AddPost(yetAnotherPost, lastRevision);
		}

		//[Test]
		//public void Post_List_Only_Returns_visible_Posts()
		//{
		//    User nextUser = new User("email@test.com", "Henrik", Company.Any);
		//}
	}
}